package regex;

import org.junit.Test;

import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则表达式demo
 *
 * @Author: zhenzhong.wang
 * @Time: 2018/3/27 17:16
 */
public class RegularExpression {

  @Test
  public void testOne() {
    String email = "zhenz@hypers.com";
    String reg = "^\\w{5}@\\w{1,6}\\.com";
    Pattern pattern = Pattern.compile(reg);
    boolean result = pattern.matcher(email).matches();
    System.out.println(result);
  }

  @Test
  public void testTwo() {
//    String test = "12345";
//    String reg = "/w*";
//    Pattern compile = Pattern.compile(reg);
//    Matcher matcher = compile.matcher(test);
//    boolean matches = matcher.matches();
//    System.out.println(matches);

    int period = new Random().nextInt(2);
    System.out.println(period);
    for (int i = 0; i < 3; i++) {
      double d = (double) (period >> 1)
          * Math.sin((double) i / (double) period
          + (6.2831853071795862D * (double) 1)
          / (double) 1);
      System.out.println(d);
    }

  }

  @Test
  public void testThree() {
    Long a = 3L;
    String b = "3";
    System.out.println(a + b);
  }

  @Test
  public void testFour() {
    String email = "zhenz@hypers.com";
    String reg = "^[a-z]{5}@[a-z0-9]{1,6}\\.com";
    Pattern compile = Pattern.compile(reg);
    Matcher matcher = compile.matcher(email);
    boolean matches = matcher.matches();
    System.out.println(matches);


  }

  @Test
  public void testFive() {
    String test = "12345";
    String reg = "\\w*";
    Pattern compile = Pattern.compile(reg);
    Matcher matcher = compile.matcher(test);
    boolean matches = matcher.matches();
    System.out.println(matches);
  }

  @Test
  public void testSix() {
    String test = "\\";
    String reg = "\\\\*";
    Pattern compile = Pattern.compile(reg);
    Matcher matcher = compile.matcher(test);
    boolean matches = matcher.matches();
    System.out.println(matches);
  }
}
